#include<stdio.h>
#include<iostream>

using namespace std;
// lapacke headers
#include <lapacke.h>
#include <lapacke_config.h>
#include <lapacke_utils.h>

extern lapack_int LAPACKE_dgeev( int matrix_order, char jobvl, char jobvr,
lapack_int n, double * a, lapack_int lda, double * wr,
double * wi, double * vl, lapack_int ldvl, double * vr,
lapack_int ldvr );

int main()
{
  int matrix_order = LAPACK_COL_MAJOR;
  char jobvl = 'N' ;
  char jobvr = 'V' ;
  int n = 50;
  int nzn = 250;
  double A[nzn];
  for(int i = 0; i < nzn; i++)
    A[i] = 0.0;
  A[0] = 3.0;
  A[1] = 1.0;
  for(int i = 1; i < n-1; i++){
    A[i*50 + i] = 3.0;
    A[i*50 + i - 1] = A[i*50 + i + 1] = 1.0;
  }
  A[249] = 3.0;
  A[248] = 1.0;
  int lda = n;
  double wr[n];
  double wi[n];
  for(int i = 0; i < n; i++)
    wr[i] = wi[i] = 0.0;
  double vl[nzn];
  int ldvl = n ;
  double vr[nzn];
  int ldvr = n ;

  int info = LAPACKE_dgeev(matrix_order,jobvl,jobvr,n,A,lda,wr,wi,vl,ldvl,vr,ldvr);
  if (info == 0 ){
    int i = 0 ;
    int j = 0 ;
    for (i = 0 ;i < n;i ++ ){
      printf( " eigenvalue %d:\n " ,i);
      printf( " %.6g + i %.6g \t " ,wr[i],wi[i]);
      printf( " right eigenvector: " );
      for (j = 0 ;j < ldvr;j ++ )
	printf( " %.6g \t " ,vr[i * 4 + j]);
      printf( " \n " );
    }
    printf( " SUCCESS\n " );
  }

  return 0 ;
};
